#include <iostream>

using std::cout;
using std::endl;

void fun(int *arr, int i, int len)
{
    if(i == len){
        for(int k{}; k < len; k++){
            cout << arr[k] << " ";
        }
        cout << endl;
    }else{
        for(int k{i}; k < len; k++){
            int tmp = arr[i]; 
            arr[i] = arr[k];
            arr[k] = tmp;
            fun(arr, i + 1, len);
            arr[k] = arr[i];
            arr[i] = tmp;
        }
    }
}

int main(int args, char *argv[])
{
    int arr[] = {1, 2, 3, 4};
    int len = sizeof(arr) / sizeof(int);
    fun(arr, 0, len);
    return 0;
}